import 'package:flutter/material.dart';

enum IconTextType {
  ///上图下文本样式
  iconTextVerticalType,

  ///上文本下图样式
  textIconVerticalType,

  ///左文本右图样式
  textIconHorizontalType,

  ///右文本左图样式
  iconTextHorizontalType,
}

class KqIconTextGroupButton extends StatefulWidget {
  /// 点击事件
  final GestureTapCallback? onTap;

  /// 水平左右padding，默认0
  final double? horizontalPadding;

  /// 垂直左右padding，默认0
  final double? verticalPadding;

  /// icon 与 text 之间的间距,默认：4
  final double? spacing;

  /// 显示样式 默认：上图下文本样式
  final IconTextType type;

  /// icon
  final Widget icon;

  /// text
  final Widget text;

  final MainAxisAlignment mainAxisAlignment;

  const KqIconTextGroupButton(
      {this.onTap,
      this.horizontalPadding = 0,
      this.verticalPadding = 0,
      this.spacing = 4,
      this.type = IconTextType.iconTextVerticalType,
      this.mainAxisAlignment = MainAxisAlignment.spaceBetween,
      required this.icon,
      required this.text,
      super.key});

  @override
  State<KqIconTextGroupButton> createState() => _KqIconTextGroupButtonState();
}

class _KqIconTextGroupButtonState extends State<KqIconTextGroupButton> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: widget.onTap,
      child: Padding(
        padding: EdgeInsets.symmetric(
            horizontal: widget.horizontalPadding ?? 0,
            vertical: widget.verticalPadding ?? 0),
        child: renderTypeView(),
      ),
    );
  }

  Widget renderTypeView() {
    if (widget.type == IconTextType.iconTextVerticalType) {
      return Column(
        mainAxisAlignment: widget.mainAxisAlignment,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          widget.icon,
          SizedBox(
            height: widget.spacing,
          ),
          widget.text
        ],
      );
    } else if (widget.type == IconTextType.textIconVerticalType) {
      return Column(
        mainAxisAlignment: widget.mainAxisAlignment,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          widget.text,
          SizedBox(
            height: widget.spacing,
          ),
          widget.icon
        ],
      );
    } else if (widget.type == IconTextType.iconTextHorizontalType) {
      return Row(
        mainAxisAlignment: widget.mainAxisAlignment,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          widget.icon,
          SizedBox(
            width: widget.spacing,
          ),
          widget.text
        ],
      );
    } else if (widget.type == IconTextType.textIconHorizontalType) {
      return Row(
        mainAxisAlignment: widget.mainAxisAlignment,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          widget.text,
          SizedBox(
            width: widget.spacing,
          ),
          widget.icon
        ],
      );
    }
    return Container();
  }
}
